package com.li.configserve.domain.gloabreturn;

/**
 * @description:
 * @author: LiDong
 * @time: 2020/6/28 22:14
 **/
public class ResponseInfo<T> {

    /**
     * 状态码
     */
    private Integer code;
    /**
     * 信息
     */
    private String message;
    /**
     * 返回结果
     */
    private T data;

    public ResponseInfo() {
    }

    public ResponseInfo(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseInfo(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public ResponseInfo(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }


    /**
     * 失败
     *
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> ResponseInfo<T> error(Integer code, String message) {
        return new ResponseInfo<>(code, message);
    }

    /**
     * 成功
     *
     * @param code
     * @param message
     * @return
     */
    public static <T> ResponseInfo<T> success(Integer code, String message) {
        return new ResponseInfo<>(code, message);
    }

    /**
     * 成功
     *
     * @param code
     * @param object object
     * @return
     */
    public static <T> ResponseInfo<T> success(Integer code, T object) {
        return new ResponseInfo<>(code, object);
    }


    /**
     * 成功标志
     *
     * @param code
     * @param message
     * @param object
     * @return
     */
    public static <T> ResponseInfo<T> success(Integer code, String message, T object) {
        return new ResponseInfo<>(code, message, object);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseInfo{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
